package com.dlc.felear.xiaoensale.customView;

import android.app.Dialog;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.dlc.felear.xiaoensale.R;


public class ShowTispMsgDialog extends Dialog implements View.OnClickListener , Handler.Callback {
    private Button btnC;
    private TextView tvTitle, tvMsg;
    private Context context;
    private Handler handler;

    public ShowTispMsgDialog(@NonNull Context context) {
        super(context);
        initView(context);
    }

    public ShowTispMsgDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        initView(context);
    }

    private void initView(Context context) {
        this.context = context;
        handler=new Handler(this);
        View root = LayoutInflater.from(context).inflate(R.layout.show_tisp_msg_dialog, null);
        setContentView(root);
        setCanceledOnTouchOutside(true);
        tvMsg = findViewById(R.id.tv_d_msg);
    }

    /**
     * 设置提示内容
     *
     * @param info
     */
    public void setMsg(String info) {
        if (tvMsg != null) {
            tvMsg.setText(info);
        }
    }


    public void setDialog(String msg) {
        setTitle(msg);
        show();
    }
    public void setDialog(String msg,int daley) {
        handler.sendEmptyMessageDelayed(1211,daley);
        setMsg(msg);
        show();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_d_confirm:
                dismiss();
                break;
            default:
        }
    }

    public void closeDialog(){
        dismiss();
    }

    @Override
    public boolean handleMessage(Message msg) {
        dismiss();
        return false;
    }
}
